package com.pbdevj.ssm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pbdevj.ssm.bean.Employee;
import com.pbdevj.ssm.bean.EmployeeExample;
import com.pbdevj.ssm.bean.EmployeeExample.Criteria;
import com.pbdevj.ssm.dao.EmployeeMapper;
import com.pbdevj.ssm.service.EmployeeService;

@Service("employeeServiceImpl")
public class EmployeeServiceImpl implements EmployeeService
{

	@Autowired
	private EmployeeMapper employeeMapper;
	
	@Override
	public List<Employee> getAll()
	{
		return this.employeeMapper.selectByExampleWithDept(null);
	}

	@Override
	public void saveEmployee(Employee employee)
	{
		this.employeeMapper.insertSelective(employee);
	}

	@Override
	public boolean checkedEmpName(String empName)
	{
		EmployeeExample example = new EmployeeExample();
		
		example.createCriteria().andEmpNameEqualTo(empName);
		
		long count = this.employeeMapper.countByExample(example);
		
		if(count > 0)
		{
			return false;
		}
		else
		{
			return true;
		}
	}

	@Override
	public Employee getEmployeeById(Integer id)
	{
		return this.employeeMapper.selectByPrimaryKeyWithDept(id);
	}

	@Override
	public void updateEmployee(Employee employee)
	{
		this.employeeMapper.updateByPrimaryKeySelective(employee);
	}

	@Override
	public void deletEmployeeById(Integer id)
	{
		this.employeeMapper.deleteByPrimaryKey(id);
	}

	@Override
	public void deleteBatchedEmployee(List<Integer> list)
	{
		EmployeeExample employeeExample = new EmployeeExample();
		
		Criteria criteria = employeeExample.createCriteria();
		
		criteria.andEmpIdIn(list);
		
		this.employeeMapper.deleteByExample(employeeExample);
	}

}
